<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!doctype html>
<html>
<head>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		 <div class="iboxtitle">
             <span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷后业务>保险业务>到期预警</span>
         </div>
         <div class="ibox-content ibox-zxsearchqu">
               <div class="row">
					<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
						  <input type="text" placeholder="客户名" id="nameCus" name="nameCus" class="form-control" value="">
					</div>
					<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
						 <input type="text" placeholder="身份证号码" id="idnoCus" name="idnoCus" class="form-control" value="">
					</div>
					<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
						<input type="text" placeholder="档案编号" id="noRecord" name="noRecord" class="form-control" value="">
					</div>
					<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
						<button class="zhixcx" type="button" onclick="query();">执行查询</button>
						<button class="zhixcx" type="button" onclick="applyPaidan();">申请派单</button>
					</div>	
				</div>
          </div>
          <div class="ibox-content">	
	          	<div class="jqGrid_wrapper">
		             <table id="table_list_1"></table>
		             <div id="pager_list_1"></div>
	         	</div>
          </div>
	</div>
	<!-- 申请派单 -->
    <%@include file="/jsp/comm_allocation_apply_include.jsp"%>
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>
	<!-- jqGrid -->
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>	
    <!--
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
	    var winWidth = $(window).width();
		var winHeight = $(window).height();
		
	    jQuery(function($) {  
	    	getData();
	    });
	    
	    var getData = function(){
	        var winWidth = $("#table_list_1").parent('div.ibox-content').width();
   	   	    var winHeight = document.body.offsetHeight - 300;
  		    var win = winWidth / 11 - 20;
  	 	    $.jgrid.defaults.styleUI = 'Bootstrap';
		  	jQuery("#table_list_1").jqGrid({
				url:'${basePath}/DhInsuranceRenewalController/list',
		        datatype : "json",
		        colNames : [ '主键','业务ID','保险到期日', '剩余天数', '客户姓名','身份证号码','投保状态','投保状态','档案编号', '保险公司','年度','车辆', '车价', '业务员','操作人'],
		        colModel : [ 
	                     {name: 'replaceId', index: 'id', hidden:true},
	                     {name: 'busiId', index: 'busiId', hidden:true},
	            		 {name: 'dateDue',index: 'dateDue',width: 170,align: "center",formatter:function(a,b,c){
	                    	 return  a ? formateStringDate(a) : '-';
	                     }},
	            		 {name: 'dateDue',index: 'dateDue',width: 130,align: "center",formatter:function(a,b,c){
	                    	 return  a ? dateDiff(a):"-";
	                     }},
	                     {name: 'nameCus',index: 'nameCus',width: 130,align: "center"},
	            		 {name: 'idnoCus',index: 'idnoCus',width: 170,align: "center"},
	            		 {name: 'statusRenewal',index: 'statusRenewal', hidden:true},
	            		 {name: 'statusRenewalDisplay',index: 'statusRenewal',width: 130,align: "center"},
	            		 {name: 'noRecord',index: 'noRecord',width: 130, align: "center"},
	            		 {name: 'nameCompanyDisplay',index: 'nameCompany',width: 300,align: "center"},
	                     {name: 'year',index: 'year',width: 130,align: "center"},
	                  	 {name: 'nameCar',index: 'nameCar',width: 130,align: "center"},
	                  	 {name: 'price',index: 'price',width: 130,align: "center"},
	               		 {name: 'nameSalesman',index: 'nameSalesman',width: 130,align: "center"},
	            		 {name: 'operatorName',index: 'operatorName',width: 130,align: "center"}
	                   ],
	              mtype : "post",
	              height: winHeight,
	              width:winWidth,  
	              autowidth: false,
	              shrinkToFit: false,
	              rowNum: 15,
	              rowList: [15, 30, 45],
	              viewrecords: true,
	              pager: "#pager_list_1",
	              hidegrid: false,
	              multiselect : false,
	              altRows:true,
			      altclass:'someClass',
	              ondblClickRow:function(rowId,v,e)
	              {
	            	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
	            	  var insuranceRenewalId = rowData.replaceId;
	            	  var busiId = rowData.busiId;
	            	  window.location.href="${basePath}/DhInsuranceRenewalViewController/insuranceRenewalDetail?id=" + busiId + "&insuranceRenewalId="+insuranceRenewalId;            	  
	              },
	              jsonReader : {
	            	  root:"result.rows",
	            	  page: "result.page",
	            	  total: "result.total",
	            	  records: "result.records",
	            	  repeatitems: false,
	            	  id: "replaceId"
	              },
	              loadComplete:function(datas){
		         	  if (datas.flag == "100100") {
		                   layer.msg("查询成功!", {icon: 6, time: 1000});
		                   return;
		               }
		         	  if(datas.flag == '100802') {
		 				  top.location.href = thisLoginUrl;
		 				  return;
		 			  }
		         	  layer.msg(datas.message, {icon: 2});
		           }
		      });
	    }	    
	    
	    window.onresize = function()
	    {
	    	$("#table_list_1").setGridWidth($(window).width()-80);
	    }
	    
	    var query = function()
	    {
	    	var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
	    	var data = {};
	    	data.nameCus = document.getElementById('nameCus').value || '';
	    	data.idnoCus = document.getElementById('idnoCus').value || '';
	    	data.noRecord = document.getElementById('noRecord').value || '';
	    	$.extend(postData, data);
	    	refresh();
	    }
	    
	    var refresh = function()
	    {
	    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}]);
	    }
	    
	    function formateStringDate(sDate1){
	    	if(!sDate1 || sDate1 == ''){
	    		return '-';
	    	}
	    	var aDate  =  sDate1.split(" ");
	    	return aDate[0];
	    }
	    
	   //计算天数差的函数，通用  
	    function dateDiff(sDate1){
		    if(sDate1 && sDate1 != ''){
		        var  aDate,  oDate1,  iDays  
		        aDate  =  sDate1.split("-")  
		        oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2].split(" ")[0]  +  '-'  +  aDate[0]) //转换为12-18-2006格式  
		        
		        sDate2  =  new  Date(); 
		        var year2 = sDate2.getFullYear();
		        var month2 = sDate2.getMonth() + 1;
		        var day2 = sDate2.getDate();
		        var oDate2 = new  Date(month2 + '-' + day2 + '-' + year2 );
		        
		        var diffDate = (oDate1  -  oDate2)  /  1000  /  60  /  60  /24;//把相差的毫秒数转换为天数  
		        var iDays  =  parseInt(diffDate);
		        if(iDays > 0){
		        	return iDays;
		        } else if(iDays < 0){
		        	return '<span style="color:#FC1515;">已超期'+  Math.abs(iDays) + '天</span>';
		        } else {
		        	return '<span style="color:#FC1515;">今日到期</span>';
		        }
		    } else {
		    	return '-';
		    }
	    } 
	   
	   //申请派单demo
	  function applyPaidan(){
		   layer.prompt({
			   title: '请输入派单数量', 
			   formType: 0,
			   value: '10',
			  }, 
			  function(value, index, elem){
				  var reg = /^[1-9]\d*$/;
				  if(value >= 1 &&  value <= 10 && reg.test(value)){
			     	layer.close(index);
			     	$.dpAjax({
	           			url:'${basePath}/DhInsuranceRenewalController/applyToAllCation',
            			data:{"allocationNum":value},
           				success: function(datas){
           					layer.msg('派单成功!', {icon: 6,time:3000});
           				}
           			});
				  }else{
					  layer.msg("请输入1-10之间的正整数!", {icon: 5, time: 1000});
				  }
		   });
	   }
    </script>
</body>
</html>
